<template>
  <div class="user">
    <el-card class="box-card" v-if="status === 'index'">
      <el-row>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getData"
          v-if="has('challengeBoxGoodsLevels/index')"
          >搜索</el-button
        >
      </el-row>
      <el-table
        :data="data.data"
        v-loading="table_loading"
        style="width: 100%;margin:10px auto"
        size="mini"
        :header-cell-style="{ background: '#f3f8fe', color: '#333' }"
      >
        <el-table-column
          prop="id"
          label="id"
          fixed
          align="center"
        ></el-table-column>
        <el-table-column label="级别名称" prop="name" align="center">
        </el-table-column>
<!--        <el-table-column label="图片" align="center">-->
<!--          <template slot-scope="scope"> </template>-->
<!--        </el-table-column>-->

        <el-table-column
          prop="created_at"
          label="时间"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="updated_at"
          label="修改时间"
          align="center"
        ></el-table-column>
<!--        <el-table-column fixed="right" label="操作" align="center" width="300">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button-->
<!--              type="primary"-->
<!--              size="mini"-->
<!--              icon="el-icon-edit"-->
<!--              @click="detail(scope.row.id)"-->
<!--              v-if="has('challengeBoxGoodsLevels/show')"-->
<!--            ></el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <el-pagination
        background
        style="text-align:center;margin:20px 0;"
        :current-page="searchParams.page"
        :page-sizes="pageSizes"
        layout="total,prev, pager, next,sizes"
        :total="data.total"
        @size-change="changeSize"
        @current-change="changePage"
      ></el-pagination>
    </el-card>
  </div>
</template>

<script>
import api from "../../api/api.js";
export default {
  name: "user",
  data() {
    return {
      status: "index", // 页面控制
      fanStatus: false,
      data: [], // 表格诗句
      table_loading: true, // 表格加载中
      loading: false, //全局加载中
      detailStatus: false,
      pageSizes: [10, 20, 50, 100, 200, 500, 800, 1000, 2000], // 每页条数默认10
      searchParams: {
        // 搜索参数
        page: 1,
        limit: 10
      },
      editParams: {
        nickname: "",
        gender: 2,
        country: "",
        city: "",
        province: "",
        created_at: "",
        avatar: "",
        account: {}
      }
    };
  },
  created() {
    this.getData();
    this.getLevel();
  },

  methods: {
    // 查看大图
    bigImage(url) {
      this.$alert("图片", {
        message: "<img  src=" + url + " style='height:200px;width:200px'>",
        dangerouslyUseHTMLString: true
      });
    },
    // 加载中
    load() {
      this.loading = this.$loading({
        lock: true,
        text: "数据加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
    },

    // 取消加载
    unload() {
      this.loading.close();
    },
    // 获取所有数据
    getData() {
      this.table_loading = true;
      api.challengeBoxGoodsLevels
        .index({ params: this.searchParams })
        .then(res => {
          if (res.data.code === 200) {
            this.table_loading = false;
            this.data = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 重置搜索参数重新搜索
    reset() {
      this.init();
      this.getData();
    },
    // 初始化
    init() {
      this.status = "index";
    },
    // 改变每页条数时
    changeSize(limit) {
      this.searchParams.limit = limit;
      this.getData();
    },
    // 改变当前页码时
    changePage(page) {
      this.searchParams.page = page;
      this.getData();
    },
    // 添加页面
    detail(id) {
      this.loading = true;
      api.challengeBoxGoodsLevels
        .show(id, this.searchParams)
        .then(res => {
          if (res.data.code === 200) {
            this.loading = false;
            // this.detailStatus = true;
            this.status = "add";
            this.editParams = res.data.data;
          }
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>

<style scoped lang="less">
.user {
  margin: 0 auto;
  .search {
    margin: 0 auto 10px auto;
  }
  .user_detail {
    display: flex;
    justify-content: space-between;
    .user_info,
    .account_fans {
      width: 48%;
    }
    .account_fans {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }
  }
}
</style>
